--
-- Author: ping.wang
-- Date: 2018-07-06 13:45:58
--
-- AuctionView
--
local TabsBtn = require("app.widget.TabsBtn")
local AuctionProductPanel = import(".AuctionProductPanel")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.AuctionUI

function ClassRef:init()
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)


    self._currentSelectTabIdx = self._data or 1

    self._productPanel = AuctionProductPanel.create(self._ui.product)

    self._productPanel:setVisible(true)

    local btns = {}
    for i = 1,2 do
        btns[i] = self._ui.Panel_tab:getChildByName("selected_btn_"..i)
    end

    local function onTabsBtn(index, btn)
        self:_refreshViewByIndex(index)
    end

    self._tabsBtn = TabsBtn.new(btns, onTabsBtn, self._currentSelectTabIdx)
end

function ClassRef:getProductPanel()
    return self._productPanel
end

--根据Idx显示不同的界面 1位普通商品 2为竞价商品
function ClassRef:_refreshViewByIndex(idx)
    if self._currentSelectTabIdx ~= idx then
        self._currentSelectTabIdx = idx
        --切换普通商品和竞价商品的时候需要设置过滤条件初始化
        self._productPanel:resetSelectFilter()
        executeFunc(self._onOperate, "showProductPanelByTabIdx",self._currentSelectTabIdx)
    end
end

function ClassRef:getCurrentTabId()
    return self._currentSelectTabIdx
end

function ClassRef:remove()
    self._productPanel:remove()
end

--刷新商品界面 {curPageIdx = self._curPageIdx,curPageMax = self._curPageMax, productList = showData}
function ClassRef:refreshProductPanel(data)
    data.showIdx = self._currentSelectTabIdx
    --dump(data)
    self._productPanel:refresh(data)
end

function ClassRef:switchChannel(index)
    self._tabsBtn:setSelected(index)
end

return ClassRef
